import 'package:get/get.dart';
import 'package:sp_util/sp_util.dart';
import 'package:yp/services/api.dart';

import '../../../helper.dart';
import '../../../logic.dart';
import '../../../router.dart';
import 'state.dart';

class ModifyPhoneSuccessLogic extends GetxController {
  final ModifyPhonseSuccessState state = ModifyPhonseSuccessState();

  @override
  void onInit() {
    super.onInit();
    state.phone = Get.arguments['phone'];
    state.code = Get.arguments['code'];
    state.token = Get.arguments['token'];
    final GlobalLogic logic1 = Get.put(GlobalLogic());
    Future.delayed(Duration(seconds: 1), () {
      logic1.logout();
    });
  }

  /// 登录
  void sure() {
    var params = {
      "channel_num_id": 2192,
      "mobile": state.phone,
      "sms_verify_code": state.code,
      "sms_verify_token": state.token,
      "sms_verify_type": "login",
      'use_platform': 2
    };
    Api.registMember(params).listen((event) {
      if (event["code"] != 0) {
        toast(event["message"]);
      } else {
        SpUtil.putString('empeName', event["usr_name"]);
        SpUtil.putInt('empeNumId', event["usr_num_id"]);
        SpUtil.putString('token', event["access_token"]);
        SpUtil.putString('number', state.phone);
        toast("登录成功");
        Get.offAllNamed(RouteConfig.main);
      }
    });
  }
}
